<?php

namespace App\Http\Controllers;

use App\Models\EnergyStorager;
use Illuminate\Http\Request;

class EnergyStoragersController extends Controller
{
    public function index(Request $request)
    {
        $data = EnergyStorager::enterprise()->with('energyStoragerStation')->requestCriteria($request)->paginate($request->query('limit'));
        return $this->respondSuccess($data);
    }

    public function store(Request $request)
    {
        $this->validate($request, [
            'energy_storager_station_id' => 'required',
            'device_id' => 'required',
        ]);

        $enterprise = EnergyStorager::create($request->input());
        return $this->respondSuccess($enterprise);
    }

    public function show(EnergyStorager $energyStorager)
    {
        return $this->respondSuccess($energyStorager->load('energyStoragerStation'));
    }

    public function update(Request $request, EnergyStorager $energyStorager)
    {
        $data = $energyStorager->update($request->input());
        return $this->respondSuccess($data);
    }

    public function destroy(EnergyStorager $energyStorager)
    {
        $data = $energyStorager->delete();
        return $this->respondSuccess($data);
    }
}
